﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Collections;
using System.Threading;

namespace CUIT.GraduationProject.ToolBoxSystem.PropertyLib
{
    public partial class PropertyLibForm : UserControl
    {
        enum States { Compressed = 1, Compressing, Extended, Extending };

        private Button ScrollButton1 = new Button();
        private Button ScrollButton2 = new Button();
        private int ButtonHeight = 22;//18;
        private int XOffset = 22;
        private int YOffset = 20;
        private int RightMargin = 5;
        private int Acceleration = 2;
        private bool Bounce = true;
        private int ScrollButtonX;
        private int ButtonWidth;
        private int ListWidth;
        private int Delay = 2000;
        private System.Windows.Forms.Splitter splitter1;
        private bool DoneMove = true;
        private System.Windows.Forms.ToolTip toolTip;
        private bool Retreat = true;
        private bool RetreatCommand = false;
        private bool ExpandCommand = false;
        private string Separator = ".";
        private int state = (int)States.Extended;
        private System.Windows.Forms.MenuItem Menu_Dock_Left;
        private System.Windows.Forms.MenuItem Menu_Dock_Right;
        private System.Windows.Forms.MenuItem Menu_Autohide;
        private System.Windows.Forms.MenuItem Menu_Hide;
        private System.Windows.Forms.MenuItem Menu_About;
        private ContextMenu CMenu = null;

        public delegate void OnToolBoxClick(int TabIndex, int ItemIndex);
        public delegate void OnToolBoxTabChanged(int TabIndex);
        public delegate void OnToolBoxStateChanged(int State);

        private OnToolBoxClick OnTBClick = null;
        private OnToolBoxTabChanged OnTBTabChanged = null;
        private System.Windows.Forms.Panel panel;
        private System.Windows.Forms.PictureBox Picture;
        private System.Windows.Forms.ContextMenu contextMenu;
        private System.Windows.Forms.ImageList imageList1;
        private System.Windows.Forms.Timer timer1;
        private OnToolBoxStateChanged OnTBStateChanged = null;

        private ArrayList arrMoveList = new ArrayList();
        private ArrayList arrSizeList = new ArrayList();
        private int delay = 0;
        private int sbdelay = 0;

        /// <summary>
        ///  初始化
        /// </summary>
        public PropertyLibForm()
        {
            InitializeComponent();
        }


        #region user32.dll
        //导入user32.dll
        [System.Runtime.InteropServices.DllImport("user32")]
        //声明API函数
        private static extern bool AnimateWindow(IntPtr hwnd, int dwTime, int dwFlags);
        #endregion

        #region 常量

        // 正面_水平方向
        const int AW_HOR_POSITIVE = 0x0001;

        // 负面_水平方向
        const int AW_HOR_NEGATIVE = 0x0002;

        // 正面_垂直方向
        const int AW_VER_POSITIVE = 0x0004;

        // 负面_垂直方向
        const int AW_VER_NEGATIVE = 0x0008;

        // 由中间四周展开或
        const int AW_CENTER = 0x0010;

        // 隐藏对象
        const int AW_HIDE = 0x10000;

        // 显示对象
        const int AW_ACTIVATE = 0x20000;
       
        // 拉幕滑动效果
        const int AW_SLIDE = 0x40000;

        #endregion

        #region 判断方向
        public int IsHorOrVer(int pos)
        {
            int rtn = 0;
            //判断是正方向还是反方向
            if (pos.Equals(0))
            {
                //判断是横向还是纵向
                if (true)
                    rtn = AW_HOR_POSITIVE;
                else rtn = AW_VER_POSITIVE;
            }
            else if (pos.Equals(1))
            {
                //判断是横向还是纵向
                if (true)
                    rtn = AW_HOR_NEGATIVE;
                else rtn = AW_VER_NEGATIVE;
            }
            return rtn;
        }
        #endregion

        /// <summary>
        ///  加载
        /// </summary>
        /// <param name="sender">sender</param>
        /// <param name="e">e</param>
        private void PropertyLib_Load(object sender, EventArgs e)
        {
            ControlProperty ctr = new ControlProperty();
            ctr.Name = "";
            ctr.Size = new Size(10, 10);
            ctr.Location = new Point(1137, 0);
            ctr.Visible = true;
            ctr.BackColor = "red";
            propertyGrid_Pro.SelectedObject = ctr;
        }

        /// <summary>
        ///  设置大小
        /// </summary>
        /// <param name="size">大小</param>
        public void SetSize(Size size)
        {
            this.Size = size;
        }

        /// <summary>
        ///  时间控件触发
        /// </summary>
        /// <param name="sender">sender</param>
        /// <param name="e">e</param>
        private void timerRoll_Tick(object sender, EventArgs e)
        {
            //#region 老的逻辑

            //////Point pt = this.PointToClient(MousePosition);
            //////Rectangle rect = new Rectangle(pt, new Size(1, 1));
            //////bool MouseOver = (ClientRectangle.IntersectsWith(rect) && !panel.ClientRectangle.IntersectsWith(rect));

            //////if (MouseOver) ExpandCommand = true;

            //////if (arrMoveList.Count > 0)
            //////{
            //////    DoneMove = false;
            //////}
            //////else
            //////{
            //////    DoneMove = true;
            //////}
            //////for (int i = 0; i < arrMoveList.Count; i++)
            //////{
            //////    MoveObject mo = ((MoveObject)arrMoveList[i]);
            //////    mo.Increment_State();
            //////    if (mo.faze == mo.endfaze)
            //////    {
            //////        arrMoveList.RemoveAt(i);
            //////        i--;
            //////    }
            //////}
            //////for (int i = 0; i < arrSizeList.Count; i++)
            //////{
            //////    SizeObject so = ((SizeObject)arrSizeList[i]);
            //////    so.Increment_State();
            //////    if (so.faze == so.endfaze)
            //////    {
            //////        arrSizeList.RemoveAt(i);
            //////        i--;
            //////    }
            //////}
            //#endregion
            //////Thread.Sleep(1900);
            //if (timerRoll.Interval == 20)
            //{
            //    // 动画——窗体向上拖拉
            //    AnimateWindow(this.Handle, 12000, AW_SLIDE | AW_HIDE | IsHorOrVer(0));
            //}
          
        }

        public void BtnPropertyClick()
        {
            // 动画——窗体向下拖拉
            AnimateWindow(this.Handle, 1000, AW_SLIDE | AW_ACTIVATE | IsHorOrVer(1));
        }
    }
}
